package emall.token.client;

import com.alibaba.fastjson.JSON;
import emall.token.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import utils.ResponseBean;
import utils.ResultCode;

@Component
public class UserClient {
    @Autowired
    private RestTemplate restTemplate;

    public User queryUser(String username,String password){

        String str = restTemplate.getForObject("http://emall-user-service/user/queryUser/"+username+"/"+password,String.class);
        ResponseBean responseBean=JSON.parseObject(str, ResponseBean.class);
        if(responseBean.getCode().equals(ResultCode.FIND_DATA_FAILURE)){
            return null;
        }
        User user=JSON.parseObject(responseBean.getData().toString(),User.class);

        return user;

    }
}
